package com.iretailer.report.quartz.horizon.wsSubscribe;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.util.Map;

/**
 * @Auther: xjw
 * @Date: 2019/10/17 0017 15:11
 * @Description:
 */
public class HorizonWsClient extends WebSocketClient {
    private final static Logger log = LoggerFactory.getLogger(HorizonWsClient.class);
    private Subscribe subscribe;

    public HorizonWsClient(Subscribe subscribe) {
        super(subscribe.getWsURI(), subscribe.getWsHeaders());
        this.subscribe = subscribe;
    }

    @Override
    public void onOpen(ServerHandshake serverHandshake) {
        log.info("---- subscribe webSocket is open {} -----", subscribe.getClientId());
    }

    @Override
    public void onMessage(String message) {
        this.subscribe.processMessage(message);
    }

    @Override
    public void onClose(int i, String s, boolean b) {
        log.info("---- subscribe webSocket is close {} -----", subscribe.getClientId());
    }

    @Override
    public void onError(Exception e) {
        log.error(e.getMessage(), e);
    }
}
